﻿using Bricks.Business.Service;
using Bricks.Site.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using Bricks.Component.Utils.Extensions;
using System.Web;
using System.Web.Mvc;
using Bricks.Component.Utils;
using System.Text;
using System.Xml;
using System.Collections;
using System.Configuration;

namespace Bricks.Site.Web.Controllers
{
    /// <summary>
    /// 涵洞统计
    /// </summary>
    [Export]
    public class CulvertStatisticsController : BaseController
    {
        //
        // GET: /CulvertStatistics/

        #region 属性
        [Import]
        public IUserOrgService UserOrgService { get; set; }
        [Import]
        public IOrgInfoService OrgInfoService { get; set; }
        [Import]
        public ICulvertStatisticsService CulvertStatisticsService { get; set; }
        [Import]
        public IFlowNodeService FlowNodeService { get; set; }

        [Import]
        public IFlowUtilsService FlowUtilsService { get; set; }

        [Import]
        public IBaklogTaskService BaklogTaskService { get; set; }
        #endregion

        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            ConstructToolsForList();
            ContractFilterView contractFilterView = new ContractFilterView();
            contractFilterView.UserType = "1";
            //ViewBag.ToolBarInfo = CommonUtils.ScheduleManagementUtils.ConstructToolsAndSetView(contractFilterView, User.Identity.Name, base.GetUserMenuActions(), "YearPlanList");
            return View(contractFilterView);
        }

        private void ConstructToolsForList()
        {
            StringBuilder sb = new StringBuilder();
            var orgs = (from u in UserInfoService.Users
                        join uo in UserOrgService.UserOrgs on u.ID equals uo.UserID
                        join o in OrgInfoService.Orgs on uo.OrgID equals o.ID
                        where u.UserName == User.Identity.Name
                        select o).ToList();
            if (orgs.Count() > 0)
            {
                string requestDepartmentListForSectionSalary = ConfigurationManager.AppSettings["RequestDepartmentListForCulvertStatistics"] as string;
                foreach (var orgInfo in orgs)
                {
                    if (CommonUtils.FlowFilterAndRequestUtils.IsHasOrgCodeAndUserNameInStr(requestDepartmentListForSectionSalary, orgInfo.OrgCode, User.Identity.Name))
                    {
                        List<UIFunctionView> menuActions = base.GetUserMenuActions();
                        foreach (UIFunctionView item in menuActions)
                        {
                            string btn = "<a href='javascript:void(0)' id='btn" + item.ActionCode + "' class='easyui-linkbutton' onclick='" + item.MenuCode + "." + item.ActionCode + "()' data-options='plain:true,iconCls:\"" + item.Icon + "\"'>" + item.ActionName + "</a>";
                            sb.Append(btn);
                        }
                        break;
                    }
                }
            }
            ViewBag.ToolBarInfo = sb.ToString();
        }

        /// <summary>
        /// 获取涵洞汇总列表
        /// </summary>
        /// <param name="projectID"></param>
        /// <param name="contractID"></param>
        /// <returns></returns>
        public ActionResult GetCulvertTotalList(string projectID, string contractID)
        {
            List<CulvertStatisticsView> list = new List<CulvertStatisticsView>();
            if (!String.IsNullOrEmpty(projectID) && !String.IsNullOrEmpty(contractID))
            {
                Guid projectGuid = projectID.ToGuid();
                Guid contractGuid = contractID.ToGuid();
                list = CulvertStatisticsService.GetCulvertTotalList(projectGuid, contractGuid);
            }
            return Json(list, "text/html");
        }

        /// <summary>
        /// 获取涵洞明细列表
        /// </summary>
        /// <param name="culvertID"></param>
        /// <returns></returns>
        public ActionResult GetCulvertDetailList(string culvertID, string newCulvertID)
        {
            List<CulvertStatisticsDetailView> list = new List<CulvertStatisticsDetailView>();
            if (!String.IsNullOrEmpty(culvertID))
            {
                Guid culvertGuid = culvertID.ToGuid();
                Guid newCulvertGuid = newCulvertID.ToGuid();

                list = CulvertStatisticsService.GetCulvertDetailList(culvertGuid, newCulvertGuid);
            }
            return Json(list, "text/html");
        }

        public ActionResult Edit(string sourceType, string processType, string sourceID, string associatedNodeCode, string lastUpdateUserDepartment, string lastUpdateUser, string culvertID, string projectID, string contractID)
        {
            CulvertStatisticsView view = null;
            string processdOrCirculatedNodeCode = string.Empty;
            string processdOrCirculatedUserDepartment = string.Empty;
            if (sourceType == "1") //新增
            {
                string flowCode = "CulvertStatistics";
                string nodeCode = FlowNodeService.GetFlowNodeByNodeCode(flowCode, true, "").NodeCode;

                view = new CulvertStatisticsView();
                //view.FlowCode = flowCode;

                //view.HandleState = "0";
                //view.SourceType = sourceType;
                //view.ProcessType = processType;
                //view.SourceID = sourceID;
                //view.AssociatedNodeCode = associatedNodeCode;
                //view.LastUpdateUserDepartment = lastUpdateUserDepartment;
                //view.LastUpdateUser = lastUpdateUser;
                //view.LastUpdateTime = DateTime.Now;
                //view.ProjectID = projectID.ToGuid();
                //view.ContractID = contractID.ToGuid();

                view.ID = Guid.NewGuid();
                view.FlowCode = flowCode;
                view.ProjectID = projectID.ToGuid();
                view.ContractID = contractID.ToGuid();
                view.RequestPerson = User.Identity.Name;
                view.RequestDate = DateTime.Now;
                view.HandleState = "0";
                view.AssociatedNodeCode = nodeCode;
                view.LastUpdateUserDepartment = lastUpdateUserDepartment;
                view.LastUpdateUser = User.Identity.Name;
                processdOrCirculatedNodeCode = view.AssociatedNodeCode;
                processdOrCirculatedUserDepartment = lastUpdateUserDepartment;

                if (!string.IsNullOrEmpty(culvertID))
                {
                    view.ID = culvertID.ToGuid();
                }
            }
            //编辑
            else
            {
                view = CulvertStatisticsService.GetCulvert(culvertID.ToGuid());
            }
            if (sourceType == "2" && processType == "1")
            {
                view.AssociatedNodeCode = associatedNodeCode;
                view.LastUpdateUserDepartment = lastUpdateUserDepartment;
                view.LastUpdateUser = lastUpdateUser;
            }

            if (sourceType == "2" || (sourceType == "3" && (processType == "1" || processType == "4" || processType == "5")))
            {
                processdOrCirculatedNodeCode = associatedNodeCode;
                processdOrCirculatedUserDepartment = lastUpdateUserDepartment;
            }
            view.CulvertDetailListJson = "";
            view.SourceType = sourceType;
            view.ProcessType = processType;
            view.SourceID = sourceID;
            view.ProcessdOrCirculatedNodeCode = processdOrCirculatedNodeCode;
            view.ProcessdOrCirculatedUserDepartment = processdOrCirculatedUserDepartment;
            ConstructTools(view);
            return View(view);
        }

        #region 根据功能权限和业务权限构造工具栏菜单按钮
        private void ConstructTools(CulvertStatisticsView culvertStatisticsView)
        {
            List<UIFunctionView> menuActions = base.GetUserMenuActions();
            StringBuilder sb = new StringBuilder();

            //过程管理列表单据双击或单击超链接，只能查看
            if (culvertStatisticsView.SourceType == "0")
            {
                SetAllDisabled(menuActions, sb);
            }
            //过程管理列表新增按钮,初始化只能保存
            else if (culvertStatisticsView.SourceType == "1")
            {
                SetOneButtonEnabled(menuActions, sb, "Save");
            }
            #region 待办列表
            else if (culvertStatisticsView.SourceType == "2")
            {
                //类型为待办
                if (culvertStatisticsView.ProcessType == "1")
                {
                    foreach (UIFunctionView item in menuActions)
                    {
                        string disabled = "";
                        if (item.ActionCode == "Withdraw" || item.ActionCode == "Receipt" || item.ActionCode == "Reminders")
                        {
                            disabled = "disabled='false'";
                        }
                        else if (item.ActionCode == "Back")
                        {
                            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(culvertStatisticsView.FlowCode, false, culvertStatisticsView.AssociatedNodeCode);
                            if (flowNodeView.NodeType == 1)
                            {
                                disabled = "disabled='false'";
                            }
                        }
                        else if (item.ActionCode == "Cancel")
                        {
                            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(culvertStatisticsView.FlowCode, false, culvertStatisticsView.AssociatedNodeCode);
                            if (flowNodeView.NodeLevel > 1 || flowNodeView.NodeType == 1)
                            {
                                disabled = "disabled='false'";
                            }
                        }
                        sb.Append(ToolButton(item, disabled));
                    }
                }
                //类型为传阅
                else
                {
                    foreach (UIFunctionView item in menuActions)
                    {
                        string disabled = "disabled='false'";
                        if (item.ActionCode == "Circulated" || item.ActionCode == "Receipt")
                        {
                            disabled = "";
                        }
                        sb.Append(ToolButton(item, disabled));
                    }
                }
            }
            #endregion

            #region 已办列表
            else if (culvertStatisticsView.SourceType == "3")
            {
                //流转已办
                if (culvertStatisticsView.ProcessType == "1")
                {
                    foreach (UIFunctionView item in menuActions)
                    {
                        string disabled = "disabled='false'";
                        if (culvertStatisticsView.HandleState != "2" && culvertStatisticsView.HandleState != "3")
                        {
                            if (item.ActionCode == "Withdraw")
                            {
                                //获取撤回到的节点信息
                                FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(culvertStatisticsView.FlowCode, false, culvertStatisticsView.ProcessdOrCirculatedNodeCode);
                                List<FlowNodeView> lstCirculationNode = new List<FlowNodeView>();
                                Dictionary<string, List<FlowNodeView>> dicConditionAndCirculationNode = new Dictionary<string, List<FlowNodeView>>();
                                bool isCanWithdraw = CanWithdraw(flowNodeView, culvertStatisticsView, lstCirculationNode, dicConditionAndCirculationNode);
                                if (isCanWithdraw)
                                {
                                    disabled = "";
                                }
                            }
                            else if (item.ActionCode == "Circulated" || item.ActionCode == "Reminders")
                            {
                                disabled = "";
                            }
                        }
                        sb.Append(ToolButton(item, disabled));
                    }
                }
                //回退已办、终止已办
                else if (culvertStatisticsView.ProcessType == "2" || culvertStatisticsView.ProcessType == "3" || culvertStatisticsView.ProcessType == "6")
                {
                    SetAllDisabled(menuActions, sb);
                }
                //本人传阅或者已阅
                else
                {
                    SetOneButtonEnabled(menuActions, sb, "Circulated");
                }
            }
            #endregion

            //流程消息
            else if (culvertStatisticsView.SourceType == "4")
            {
                SetAllDisabled(menuActions, sb);
            }

            ViewBag.ToolBarInfo = sb.ToString();
        }

        private void SetAllDisabled(List<UIFunctionView> menuActions, StringBuilder sb)
        {
            foreach (UIFunctionView item in menuActions)
            {
                sb.Append(ToolButton(item, "disabled='false'"));
            }
        }

        private void SetOneButtonEnabled(List<UIFunctionView> menuActions, StringBuilder sb, string code)
        {
            foreach (UIFunctionView item in menuActions)
            {
                string disabled = "disabled='false'";
                if (item.ActionCode == code)
                {
                    disabled = "";
                }
                sb.Append(ToolButton(item, disabled));
            }
        }

        public string ToolButton(UIFunctionView item, string disabled = "")
        {
            return "<a href='javascript:void(0)' id='btn" + item.ActionCode + "' class='easyui-linkbutton' onclick='" + item.MenuCode + "." + item.ActionCode + "()' data-options='plain:true,iconCls:\"" + item.Icon + "\"'" + disabled + ">" + item.ActionName + "</a>";
        }
        #endregion

        #region 判断是否有撤回权限
        /// <summary>
        /// 判断是否有撤回权限
        /// </summary>
        /// <param name="flowNodeView">撤回到的节点信息</param>
        /// <param name="recordID">单据ID</param>
        /// <param name="lstCirculationNode">根据withdrawNodeCode获取要流转的节点列表</param>
        /// <param name="dicConditionAndCirculationNode">根据withdrawNodeCode获取条件节点流转的节点字典</param>
        /// <returns></returns>
        private bool CanWithdraw(FlowNodeView flowNodeView, CulvertStatisticsView culvertStatisticsView, List<FlowNodeView> lstCirculationNode, Dictionary<string, List<FlowNodeView>> dicConditionAndCirculationNode)
        {
            //分析撤回到的节点的XML里面的circulationCell，获取节点Code数组
            string[] arrFlowNodeCode = GetNodeCodeByXMLForCirculation(flowNodeView.NodeXML, culvertStatisticsView.ID.ToString());

            //根据第一次获取到的节点数组，获取所有的中间经过的条件节点和流转节点
            foreach (string flowNodeCode in arrFlowNodeCode)
            {
                List<FlowNodeView> lstConditionAndCirculationNode = new List<FlowNodeView>();
                GetConditionAndCirculationNode(culvertStatisticsView.FlowCode, flowNodeCode, culvertStatisticsView.ID.ToString(), culvertStatisticsView.ProcessdOrCirculatedUserDepartment, lstCirculationNode, lstConditionAndCirculationNode);
                dicConditionAndCirculationNode.Add(flowNodeCode, lstConditionAndCirculationNode);
            }

            //判断是否流转的节点对应的每个人在待办里面都能找到
            List<BaklogTaskView> lstBaklogTask = BaklogTaskService.GetBaklogTaskByRecordID(culvertStatisticsView.ID.ToString());
            foreach (FlowNodeView circulationNode in lstCirculationNode)
            {
                string[] processDepartmentAndPersonArr = circulationNode.DefaultProcessPerson.Split(',');
                foreach (string processDepartmentAndPerson in processDepartmentAndPersonArr)
                {
                    string[] subProcessDepartmentAndPersonArr = processDepartmentAndPerson.Split('|');

                    //是否找不到待办
                    BaklogTaskView existsBaklogTaskView = lstBaklogTask.SingleOrDefault(b => b.CurrentFlowNodeCode == circulationNode.NodeCode && b.CurrentProcessPerson == subProcessDepartmentAndPersonArr[1]);
                    if (existsBaklogTaskView == null)
                    {
                        return false;
                    }

                    //是否点击了保存按钮
                    if (culvertStatisticsView.SaveState == "1")
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        /// <summary>
        /// 根据节点的XML获取流转节点Code
        /// </summary>
        /// <param name="nodeXML">节点的XML</param>
        /// <param name="recordID">单据ID</param>
        /// <returns></returns>
        private string[] GetNodeCodeByXMLForCirculation(string nodeXML, string recordID)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(nodeXML);
            XmlNodeList nodeList = doc.SelectNodes("NodeXML/circulationCell");
            string getType = nodeList[0].SelectSingleNode("getType").InnerText;
            string processNodeCode = string.Empty;
            if (getType.ToLower() == "value")
            {
                processNodeCode = nodeList[0].SelectSingleNode("cellsName").InnerText;
            }
            else
            {
                string functionName = nodeList[0].SelectSingleNode("functionName").InnerText;
                Hashtable para = new Hashtable();
                para.Add("IsGetBusinessData", true);
                para.Add("RecordID", recordID);
                XmlNode paraNode = nodeList[0].SelectSingleNode("functionParam");
                if (paraNode != null)
                {
                    para.Add(paraNode.Name, paraNode.InnerText);
                }
                processNodeCode = FlowUtilsService.ExecuteCommand(functionName, para) as string;
            }
            return processNodeCode.Split(',');
        }

        /// <summary>
        /// 获取所有的中间经过的条件节点和流转节点
        /// </summary>
        /// <param name="flowCode">流程编码</param>
        /// <param name="flowNodeCode">流程节点编码</param>
        /// <param name="recordID">单据ID</param>
        /// <param name="dicCirculationNode">记录流转节点的字典</param>
        /// <param name="lstConditionAndCirculationNode">记录条件节点和流转节点的List</param>
        private void GetConditionAndCirculationNode(string flowCode, string flowNodeCode, string recordID, string processUserDepartment, List<FlowNodeView> lstCirculationNode, List<FlowNodeView> lstConditionAndCirculationNode)
        {
            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(flowCode, false, flowNodeCode);
            lstConditionAndCirculationNode.Add(flowNodeView);
            if (flowNodeView.NodeType == 2)
            {
                //如果是条件节点，获取条件节点的XML数据并解析，递归调用
                string[] arrFlowNodeCode = GetNodeCodeByXMLForCirculation(flowNodeView.NodeXML, recordID);
                foreach (string nextNodeCode in arrFlowNodeCode)
                {
                    GetConditionAndCirculationNode(flowCode, nextNodeCode, recordID, processUserDepartment, lstCirculationNode, lstConditionAndCirculationNode);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(flowNodeView.NodeXML))
                {
                    flowNodeView.DefaultProcessPerson = GetDefaultProcessPerson(flowNodeView.NodeXML, processUserDepartment);
                }
                lstCirculationNode.Add(flowNodeView);
            }
        }

        /// <summary>
        /// 获取缺省处理人和部门
        /// </summary>
        /// <param name="docPerson">节点xml文档</param>
        /// <param name="recordID">单据ID</param>
        /// <returns></returns>
        private string GetDefaultProcessPerson(string nodeXML, string processUserDepartment)
        {
            string defaultProcessPerson = string.Empty;
            XmlDocument docPerson = new XmlDocument();
            docPerson.LoadXml(nodeXML);
            XmlNode personNode = docPerson.SelectSingleNode("NodeXML/defaultProcessPerson");
            if (personNode != null)
            {
                string processPersonGetType = personNode.SelectSingleNode("getType").InnerText;
                if (processPersonGetType == "value")
                {
                    defaultProcessPerson = personNode.SelectSingleNode("presonList").InnerText;
                }
                else
                {
                    string functionName = personNode.SelectSingleNode("functionName").InnerText;
                    Hashtable para = new Hashtable();
                    para.Add("OrgCode", processUserDepartment);
                    XmlNode paraNode = personNode.SelectSingleNode("functionParam");
                    if (paraNode != null)
                    {
                        para.Add(paraNode.Name, paraNode.InnerText);
                    }
                    defaultProcessPerson = FlowUtilsService.ExecuteCommand(functionName, para) as string;
                }
            }
            return defaultProcessPerson;
        }
        #endregion

        #region 流程操作
        /// <summary>
        /// 撤回
        /// </summary>
        /// <param name="model"></param>
        /// <param name="withdrawNodeCode"></param>
        /// <returns></returns>
        public ActionResult Withdraw(CulvertStatisticsView model, string withdrawNodeCode)
        {
            try
            {
                //获取撤回到的节点信息
                FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(model.FlowCode, false, withdrawNodeCode);
                List<FlowNodeView> lstCirculationNode = new List<FlowNodeView>();
                Dictionary<string, List<FlowNodeView>> dicConditionAndCirculationNode = new Dictionary<string, List<FlowNodeView>>();
                bool isCanWithdraw = CanWithdraw(flowNodeView, model, lstCirculationNode, dicConditionAndCirculationNode);
                if (isCanWithdraw)
                {
                    FlowUtilsService.Withdraw(flowNodeView, model.FlowCode, model.ID.ToString(), model.ProcessdOrCirculatedUserDepartment, model.RequestDate, lstCirculationNode, dicConditionAndCirculationNode);
                    return Content("Success");
                }
                else
                {
                    return Content("已经有人处理，不能撤回！");
                }
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }

        /// <summary>
        /// 终止
        /// </summary>
        /// <param name="flowCode"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Cancel(string flowCode, string id)
        {
            try
            {
                FlowUtilsService.Cancel(flowCode, User.Identity.Name, id);
                CulvertStatisticsView culvertStatisticsView = CulvertStatisticsService.GetCulvert(id.ToGuid());
                culvertStatisticsView.HandleState = "3";
                CulvertStatisticsService.Save(culvertStatisticsView, new List<CulvertStatisticsDetailView>(), false);
                return Content("Success");
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }

        /// <summary>
        /// 催办
        /// </summary>
        /// <param name="flowCode"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Reminders(string flowCode, string id)
        {
            try
            {
                FlowUtilsService.Reminders(id, flowCode, User.Identity.Name);
                return Content("Success");
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }
        #endregion

        #region 表单逻辑（Add By Luozx）
        [HttpPost]
        public ActionResult Save(CulvertStatisticsView view)
        {
            var result = new OperationResult(OperationResultType.NoChanged);
            var record = CulvertStatisticsService.CulvertStatisticses.FirstOrDefault(m => m.ID == view.ID);
            //新增
            if (record == null)
            {
                var existStatisticalCycle = CulvertStatisticsService.CulvertStatisticses.Count(m => m.StatisticalCycle == view.StatisticalCycle && m.ProjectID == view.ProjectID && m.ContractID == view.ContractID);
                if (existStatisticalCycle > 0)
                {
                    result = new OperationResult(OperationResultType.Warning, string.Format("统计周期【{0}】已经存在", view.StatisticalCycle));
                }
                else
                {
                    List<BaklogTaskView> addList = new List<BaklogTaskView>();
                    addList.Add(new BaklogTaskView()
                    {
                        ID = GuidHelper.NewGuid(),
                        RecordID = view.ID.ToString(),
                        TaskType = view.FlowCode,
                        RequestDate = view.RequestDate,
                        CurrentFlowNodeCode = view.AssociatedNodeCode,
                        CurrentProcessPersonDepartment = view.LastUpdateUserDepartment,
                        CurrentProcessPerson = view.LastUpdateUser,
                        NodeLevel = 1
                    });
                    BaklogTaskService.AddBaklogTask(addList);
                    view.LastUpdateTime = DateTime.Now;
                    view.SaveState = "1";

                    result = CulvertStatisticsService.Add(view);
                }
            }
            //修改
            else
            {
                result = CulvertStatisticsService.Modify(view);
            }
            return Json(result, "text/html");
        }

        public ActionResult Delete(string culvertID)
        {
            var result = CulvertStatisticsService.Delete(culvertID.ToGuid());
            return Json(result);
        }

        /// <summary>
        /// 获取上月的桥梁ID
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetPreStatisticalCycleCulvertID(int year, int month, string projectID, string contractID)
        {
            string preCulvertID = string.Empty;
            int preMonth = month - 1;
            string preStatisticalCycle = string.Format("{0}年{1}月", year, preMonth < 10 ? "0" + preMonth.ToString() : preMonth.ToString());
            var projectGuid = projectID.ToGuid();
            var contractGuid = contractID.ToGuid();
            var culvert = CulvertStatisticsService.CulvertStatisticses.FirstOrDefault(m => m.StatisticalCycle == preStatisticalCycle && m.ProjectID == projectGuid && m.ContractID == contractGuid);
            if (culvert != null)
            {
                preCulvertID = culvert.ID.ToString();
            }
            return Content(preCulvertID);
        }

        /// <summary>
        /// 判断统计周期是否存在
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="projectID"></param>
        /// <param name="contractID"></param>
        /// <returns></returns>
        public ActionResult IsExistStatisticalCycle(int year, int month, string projectID, string contractID)
        {
            string isExist = "false";
            string preStatisticalCycle = string.Format("{0}年{1}月", year, month < 10 ? "0" + month.ToString() : month.ToString());
            var projectGuid = projectID.ToGuid();
            var contractGuid = contractID.ToGuid();
            var culvert = CulvertStatisticsService.CulvertStatisticses.FirstOrDefault(m => m.StatisticalCycle == preStatisticalCycle && m.ProjectID == projectGuid && m.ContractID == contractGuid);
            if (culvert != null)
            {
                isExist = "true";
            }
            return Content(isExist);
        }
        #endregion
    }
}
